package com.mihoy.controller;

import com.mihoy.model.User;
import com.mihoy.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@Controller
public class UserController {

    @Resource
    private UserService userService;

    @ModelAttribute
    public User getUser() {
        return new User();
    }




    //跳转到用户登录
    @RequestMapping(value = "/userLogin")
    public String userLogin() {
        return "login";
    }


    // 用户注册的跳转
    @RequestMapping("userRegister")
    public String register() {
        return "regist";
    }

    String i = "dCdd";

    @GetMapping("index")
    public String index() {
        User user = getUser();
        user.setCode(i);
        user.setName(i);
        userService.add(user);
        return "index";
    }
}